﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace WhatCatch.Core.New
{
    public class CatchService
    {
        int threadNum = 1;

        public void CatchProduce()
        {
            TaskFactory taskDetailFactory = new TaskFactory();
            for (int i = 0; i < threadNum; i++)
            {
                taskDetailFactory.StartNew((obj) =>
                {
                    int index = (int)obj;
                    //_crawlerLog.Info($"运行线程【{index}】");

                    while (true)
                    {
                        //取一个列表url，标记读取
                        string url = "";
                        if (string.IsNullOrEmpty(url))
                        {
                            //_crawlerLog.Info($"【明细线程{index}】无明细页任务");
                            Thread.Sleep(1000);
                            continue;
                        }

                        //处理明细页
                        HtmlHandleRequest task = new HtmlHandleRequest
                        {
                            Url = url,
                            Id = "",
                            TaskId = 0
                        };
                        SendCatchTask(task);

                        Thread.Sleep(1);
                    }
                }, i);
            }
        }

        private void SendCatchTask(HtmlHandleRequest request)
        {

        }

        public void CatchConsume()
        {
            
        }

        private HtmlHandleRequest GetCatchTaskResult()
        {
            return null;
        }
    }

    public class HtmlHandleRequest
    {
        public string Id { get; set; }
        public int TaskId { get; set; }
        public string Url { get; set; }
    }
    public class HtmlHandleResponse
    {
        public HtmlHandleRequest RequestData { get; set; }
        public bool IsGet { get; set; }
        public string Html { get; set; }
    }
}
